package com.sendi.sql;

import java.lang.reflect.Field;
import java.util.HashMap;

import com.sendi.system.util.common.ReflectUtil;

public class SecondGroupByHashMap {
	
	String keyType="";
	  
	HashMap<String,Integer> intergerresult=null;
	HashMap<String,Long> longresult=null;
	HashMap<String,Float> floatresult=null;
	HashMap<String,Double> doubleresult=null;
	
	
	public SecondGroupByHashMap()
	{
		
	}
	
	public void MakeSumGroupAction(String key,Object value)
	{
		if(keyType.equalsIgnoreCase("INT"))
		{
			Integer it=intergerresult.get(key);
			if(it==null)
			{
				intergerresult.put(key,Integer.valueOf(String.valueOf(value)));
			}
			else
			{
				it=it+Integer.valueOf(String.valueOf(value));
				intergerresult.put(key, it);
			}
		}
		else if(keyType.equalsIgnoreCase("LONG"))
		{
			Long it=longresult.get(key);
			if(it==null)
			{
				longresult.put(key,Long.valueOf(String.valueOf(value)));
			}
			else
			{
				it=it+Long.valueOf(String.valueOf(value));
				longresult.put(key, it);
			}
			
		}
		else if(keyType.equalsIgnoreCase("FLOAT"))
		{
			Float it=floatresult.get(key);
			if(it==null)
			{
				floatresult.put(key,Float.valueOf(String.valueOf(value)));
			}
			else
			{
				it=it+Float.valueOf(String.valueOf(value));
				floatresult.put(key, it);
			}
			
		}
		else if(keyType.equalsIgnoreCase("DOUBLE"))
		{
			Double it=doubleresult.get(key);
			if(it==null)
			{
				doubleresult.put(key,Double.valueOf(String.valueOf(value)));
			}
			else
			{
				it=it+Double.valueOf(String.valueOf(value));
				doubleresult.put(key, it);
			}
		}
		
		
	}
	public SecondGroupByHashMap(String keyType)
	{
		this.keyType=keyType;
		if(keyType.equalsIgnoreCase("INT"))
		{
			intergerresult=new HashMap<String, Integer>();
		}
		else if(keyType.equalsIgnoreCase("LONG"))
		{
			longresult=new HashMap<String, Long>();
		}
		else if(keyType.equalsIgnoreCase("FLOAT"))
		{
			floatresult=new HashMap<String, Float>();
		}
		else if(keyType.equalsIgnoreCase("DOUBLE"))
		{
			doubleresult=new HashMap<String, Double>();
		}
		 
	}
	
	public Object  SecondGroupByresult()
	{
		Object re=null;
		if(keyType.equalsIgnoreCase("INT"))
		{
			re=intergerresult;
		}
		else if(keyType.equalsIgnoreCase("LONG"))
		{
			re=longresult;
		}
		else if(keyType.equalsIgnoreCase("FLOAT"))
		{
			re=floatresult;
		}
		else if(keyType.equalsIgnoreCase("DOUBLE"))
		{
			re=doubleresult;
		}
		return re;
	}
	
	
	public void  SetSecondGroupByresult(Object o,String key,Field accepfield)
	{
		 
		if(keyType.equalsIgnoreCase("INT"))
		{
	 		ReflectUtil.setFieldValueByReflect(o, accepfield, keyType, intergerresult.get(key));
		}
		else if(keyType.equalsIgnoreCase("LONG"))
		{
			 
			ReflectUtil.setFieldValueByReflect(o, accepfield, keyType, longresult.get(key));
		}
		else if(keyType.equalsIgnoreCase("FLOAT"))
		{
		 	ReflectUtil.setFieldValueByReflect(o, accepfield, keyType, floatresult.get(key));
		}
		else if(keyType.equalsIgnoreCase("DOUBLE"))
		{
			 
			ReflectUtil.setFieldValueByReflect(o, accepfield, keyType, doubleresult.get(key));
		}
	 
	}
	
	
	
	
	
	
	

}
